package com.sky.controller.admin;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController("adminShopController")
@RequestMapping("/admin/shop")
@Api
@Slf4j
public class ShopController {

    @Autowired
    private RedisTemplate redisTemplate;

    private static final String SHOPSTATUS = "shop_status";
    /**
     * 在管理端设置店铺状态
     *
     * @return
     */
    @ApiOperation("设置店铺状态")
    @PutMapping("/{status}")
    public Result setStatus(@PathVariable Integer status) {
        log.info("设置店铺的状态为:{}", status == 1 ? "营业中" : "打烊了");
        redisTemplate.opsForValue().set(SHOPSTATUS, status);
        return Result.success();
    }

    /**
     * 获取到店铺的营业状态
     * @return
     */
    @ApiOperation("获取店铺状态")
    @GetMapping("/status")
    public Result<Integer> getStatus(){
        Integer status = (Integer) redisTemplate.opsForValue().get(SHOPSTATUS);
        log.info("查询到的店铺的营业状态为:{}",status==1? "营业":"打烊");
        return Result.success(status);
    }
}
